using System.Collections.Generic;
using UnityEngine;
using Verse;
using RimWorld;
using Verse.Noise;

namespace RimZombieGirl
{
    public class CompAbilityEffect_CureCurse : CompAbilityEffect
    {
        public new CompProperties_CureCurse Props => (CompProperties_CureCurse)props;

        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
        {
            base.Apply(target, dest);

            // 选中的是 Pawn
            if (target.Pawn != null)
            {
                Pawn pawn = target.Pawn;

                Hediff curseHediff = pawn.health?.hediffSet?.GetFirstHediffOfDef(ZombieDefOf.RI_CurseHediff);
                if (curseHediff != null)
                {
                    float percent = Rand.Range(Props.cureCurseMin, Props.cureCurseMax)*0.1f;

                    float reduceAmount = curseHediff.Severity * percent;

                    curseHediff.Severity = Mathf.Max(0, curseHediff.Severity - reduceAmount);

                    MoteMaker.ThrowText(pawn.DrawPos, pawn.Map, $"诅咒减少 {percent:P0}");
                }
            }
            else // 选中的是地面
            {
                if (base.parent.pawn.Map.GetComponent<MapComponent_Curse>() is MapComponent_Curse comp)
                {
                    int reduceCurse = Rand.Range(Props.cureCurseMin, Props.cureCurseMax);
                    comp.ReduceTargetCurseValue(reduceCurse);
                    MoteMaker.ThrowText(dest.Cell.ToVector3Shifted(), parent.pawn.Map, $"全局诅咒 -{reduceCurse}");
                }
            }
        }
    }

}